package olive.mycourse.servlets;

import java.sql.ResultSet;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import olive.mycourse.database.DBConnector;

public class LoginPage {
	private Map parameters=null;
	private DBConnector dbc=null;
	public static String[] Keys = {};
	private String message="";
	private String userType="";
	private ResultSet result=null;
	private HttpServletRequest request=null;

	
	public LoginPage(HttpServletRequest request){
		this.request = request;
		dbc = new DBConnector();
		Boolean t;
		try {
			dbc.standBy("");
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			message=e.getMessage();
		}
	}
	
	public Boolean loginCheck() throws Exception{
		String temp,temp1;
		
		String[][] selPerson=new String[2][3]; 
		selPerson[0][0]="id";
		selPerson[0][1]="=";
		selPerson[0][2]= (String) request.getParameter("TxtUserName" );
		selPerson[1][0]="password";
		selPerson[1][1]="=";
		selPerson[1][2]=(String) request.getParameter("TxtPassword");
		result=dbc.selFromTable(selPerson, "person");	
		
		while(result.next()){
			//result.previous();
			temp= result.getString("id");
			temp1=result.getString("password");
			
				userType=result.getString("userType");
				return true; 
			}
		return false;
		} 
	
	
	public String getUserType() {
		return userType;
	}

	public ResultSet getResult() {
		return result;
	}
	
}
